use crate::websockt::WebSocketFrame;
use super::WebSocketSession;

#[async_trait::async_trait]
pub trait WebSocketHandler {
    async fn on_open(&self, sender: &WebSocketSession);
    async fn on_message(&self, sender: &WebSocketSession, msg: &str);
    async fn on_close(&self, sender: &WebSocketSession);

    async fn on_close_with_back(&self, sender: &WebSocketSession) {
        self.on_close(&sender).await;
        sender.send_frame_to_server(&WebSocketFrame::server_close());
    }
}
